package com.adv.ems.model.dto;

import lombok.Data;
import org.springframework.util.StringUtils;

@Data
public class ExcelMeterInfo {
    private String holder;
    private String meterCode;
    private String property;
    private Double value;
    private Double lastValue;
    private Double firstValue;
    private String unit;

    public static ExcelMeterInfo build(String content) {
        if (content == null || content.length() == 0) {
            return null;
        }
        if (!content.contains("::")) {
            return null;
        }
        String[] split = content.replace("{{", "").replace("}}", "").split("::");
        if (split.length != 2) {
            return null;
        }
        if (!StringUtils.hasLength(split[0]) || !StringUtils.hasLength(split[1])) {
            return null;
        }
        ExcelMeterInfo excelMeterInfo = new ExcelMeterInfo();
        excelMeterInfo.setHolder(content);
        excelMeterInfo.setMeterCode(split[0]);
        excelMeterInfo.setProperty(split[1]);
        return excelMeterInfo;
    }
}
